<?php

namespace app\app\controller;

use app\BaseController;
use app\app\model\FileModel;

class Upload extends BaseController
{
    public function index()
    {
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('file');
        // 上传到本地服务器
        $savename = \think\facade\Filesystem::disk('public')->putFile('upload', $file);
        $file_name = $file->getOriginalName();

        $res['file_id'] = $this->uuid();
        $res['file_name'] = $file_name;
        $res['file_path'] = request()->domain() . '/storage/' . $savename;
//        $res['file_path'] = str_replace('/\/', '/', );
        $res['use_count'] = "0";

        $file_moodel = new FileModel();
        $file_moodel->save($res);

        $this->success('success', $res);
    }
}
